const express = require("express");
let router = express.Router();

const DB = require("../utils/db完整.js");
const {api_url} = require("../config/config.js")


//轮播图
router.get("/banners", async(req, res, next) => {
    // let sql = `SELECT  *   FROM  e_banners WHERE isshow=1`;
    let sql = `select id, concat("${api_url}","/uploads/",image_src) as image_src ,title,isshow from e_banners where isshow=1`;
    let [err,result] = await DB(sql);
    // console.log(err);
    // console.log(result);
    if(err){
        next("请求失败");
        return
    }
    res.send({
        status:200,
        msg:"banners请求成功",
        result
    })
})


// 同步和精品课程
router.get("/courses", async(req,res,next)=>{
    let {type} = req.query;
    // console.log(type);
    let sql = `select id,cid,title,price,concat("${api_url}","/uploads/","online/",image_src) as image_src,type_name,area_name,subject_name from e_course where type=${type} limit ${type==1?8:6}`;
    let [err,result] = await DB(sql);
    if(err){
        next(`${type==1?"同步课程":"精品课程"}请求失败`);
        return
    }
    res.send({
        status:200,
        msg:`${type==1?"同步课程":"精品课程"}请求成功`,
        result
    })
})








module.exports = router;
